<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script type="text/javascript" src="${ctx}/scripts/checktool.js"></script>

<div class="spaw730nav">
	<p class="sHB00 fl">修改基本信息</p>
</div>
<div class="spalisdiv">
	<div class="spalistmater">
		<form id="f_user_info" action="<c:url value='/user/saveuser.do'/>" method="post">
			<table class="t_mid">
				<tr>
					<td class="t_mid_td11"></td>
					<td class="t_mid_td21"><div class="d_reg_error" id="div_password_error"></div></td>
					<td class="t_mid_td31"></td>
				</tr>
				<tr>
					<td class="t_mid_td1"><fmt:message key="html.register.password"/></td>
					<td  class="t_mid_td2">
						<input class="input" type="text" id="user_password" name="userInfo.password" value="${userInfo.password}" onfocus="clearErrorDiv('div_password_error')" onblur="validatePassword()"/>
						<font style="color:red;">*</font>
					</td>
					<td class="t_mid_td3">请您使用：-，_，数字，字母(6-15位)</td>
				</tr>
				<tr>
					<td class="t_mid_td11"></td>
					<td class="t_mid_td21"><div class="d_reg_error" id="div_nickname_error"></div></td>
					<td class="t_mid_td31"></td>
				</tr>
				<tr>
					<td class="t_mid_td1"><fmt:message key="html.register.nickname"/></td>
					<td class="t_mid_td2">
						<input class="input" type="text" id="user_nickname" name="userInfo.nickname" value="${userInfo.nickname}" onfocus="clearErrorDiv('div_nickname_error')" onblur="validateNickname()"/>
						<font style="color:red;">*</font>
					</td>
					<td class="t_mid_td3"></td>
				</tr>
				<tr>
					<td class="t_mid_td1">性别：</td>
					<td class="t_mid_td2">
						<select class="input" name="userInfo.gender">
							<option value="2" <c:if test="${userInfo.gender ==2}">selected="selected"</c:if>>美女</option>
							<option value="1" <c:if test="${userInfo.gender ==1}">selected="selected"</c:if>>帅哥</option>
						</select>
						<font style="color:red;">*</font>
					</td>
					<td class="t_mid_td3"></td>
				</tr>
				<tr>
					<td class="t_mid_td11"></td>
					<td class="t_mid_td21"><div class="d_reg_error" id="div_email_error"></div></td>
					<td class="t_mid_td31"></td>
				</tr>
				<tr>
					<td class="t_mid_td1"><fmt:message key="html.register.email"/></td>
					<td class="t_mid_td2">
						<input class="input" type="text" id="user_email" name="userInfo.email" value="${userInfo.email}" onfocus="clearErrorDiv('div_email_error')" onblur="validateEmail()"/>
						<font style="color:red;">*</font>
					</td>
					<td class="t_mid_td3">请您填写经常使用的Email</td>
				</tr>
				<tr>
					<td class="t_mid_td11"></td>
					<td class="t_mid_td21"><div class="d_reg_error" id="div_homeurl_error"></div></td>
					<td class="t_mid_td31"></td>
				</tr>
				<tr>
					<td class="t_mid_td1">个人主页</td>
					<td class="t_mid_td2">
						<input class="input" type="text" id="user_homeurl" name="userInfo.homeUrl" value="${userInfo.homeUrl}"/>
					</td>
					<td class="t_mid_td3">请您填写个人主页地址</td>
				</tr>
				<tr>
					<td class="t_mid_td1">生日</td>
					<td class="t_mid_td2">
						<input class="input" type="text" id="user_birthday" name="userInfo.birthday" value="<fmt:formatDate value='${userInfo.birthday}' pattern='yyyy-MM-dd'/>"/>
					</td>
					<td class="t_mid_td3">请您填写您的生日,格式如1985-12-01</td>
				</tr>
				<tr>
					<td class="t_mid_td11"></td>
					<td class="t_mid_td21"><div class="d_reg_error" id="div_qq_error"></div></td>
					<td class="t_mid_td31"></td>
				</tr>
				<tr>
					<td class="t_mid_td1">QQ</td>
					<td class="t_mid_td2">
						<input class="input" type="text" id="user_qq" name="userInfo.qq" value="${userInfo.qq}"/>
					</td>
					<td class="t_mid_td3"></td>
				</tr>
				<tr>
					<td class="t_mid_td11"></td>
					<td class="t_mid_td21"><div class="d_reg_error" id="div_msn_error"></div></td>
					<td class="t_mid_td31"></td>
				</tr>
				<tr>
					<td class="t_mid_td1">MSN</td>
					<td class="t_mid_td2">
						<input class="input" type="text" id="user_msn" name="userInfo.msn" value="${userInfo.msn}"/>
					</td>
					<td class="t_mid_td3"></td>
				</tr>
				<tr>
					<td class="t_mid_td11"></td>
					<td class="t_mid_td21"><div class="d_reg_error" id="div_tel_error"></div></td>
					<td class="t_mid_td31"></td>
				</tr>
				<tr>
					<td class="t_mid_td1">手机号码</td>
					<td class="t_mid_td2">
						<input class="input" type="text" id="user_qq" name="userInfo.tel" value="${userInfo.tel}"/>
					</td>
					<td class="t_mid_td3"></td>
				</tr>
				<tr>
					<td colspan="3" style="text-align:center;height:50px;background-color:#FFEDED;font-size: 20px;font-weight:bold">
					<a class="but82" href="javascript:saveUserInfo();">保&nbsp;&nbsp;&nbsp;存</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>

<script>
function saveUserInfo(){
	var div_nickname_error = $("#div_nickname_error").html();
	var div_email_error = $("#div_email_error").html();
	var div_password_error = $("#div_password_error").html();
	if(div_nickname_error.length == 0 &&div_email_error.length == 0 &&div_password_error.length == 0){
		$.ajax({
			type : "POST",
			url : "<c:url value='/user/saveuser.do'/>",
			data:$("#f_user_info").serialize(),
			timeout:20000,
			success : function(data){
				if($(data).find('result').text().toUpperCase().indexOf("TRUE") >= 0){
					userinfoTab(2);
				}
			},
			error: function(){
			}
		});
	}
}
function validateAccount(){
	var account = $("#user_username").val();
	if(CheckTool.checkUsername(account) == false){
		$("#div_account_error").html('<fmt:message key="html.register.error.username.pattern"/>');
		$("#div_account_error").css("display", "block");
	}else{
		$.ajax({
			type : "POST",
			url : ctx + "/h/validacc.do",
			data : "account="+account,
			dataType:"xml", 
			timeout:20000,
			sync : false,
			success : function(data){
				if($(data).find('result').text().toUpperCase().indexOf("TRUE") < 0){
					$("#div_account_error").html($(data).find('content').text());
					$("#div_account_error").css("display", "block");
				}
			},
			error: function(){
				$("#div_account_error").html('<fmt:message key="html.register.error.username.exist"/>');
				$("#div_account_error").css("display", "block");
			}
		});
	}
}

function validateNickname(){
	var nickname = $("#user_nickname").val();
	$.ajax({
		type : "POST",
		url : ctx + "/h/validnick.do",
		data : "nick="+nickname,
		dataType:"xml", 
		timeout:20000,
		sync : false,
		success : function(data){
			if($(data).find('result').text().toUpperCase().indexOf("TRUE") < 0){
				$("#div_nickname_error").html($(data).find('content').text());
				$("#div_nickname_error").css("display", "block");
			}
		},
		error: function(){
			$("#div_nickname_error").html('<fmt:message key="html.register.error.nickname.exist"/>');
			$("#div_nickname_error").css("display", "block");
		}
	});
}
function validateEmail(){
	var email = $("#user_email").val();
	if(CheckTool.checkEmail(email) == false){
		$("#div_email_error").html('<fmt:message key="html.register.error.email.pattern"/>');
		$("#div_email_error").css("display", "block");
	}
}
function validatePassword(){
	var password = $("#user_password").val();
	if(CheckTool.checkPassword(password) == false){
		$("#div_password_error").html('<fmt:message key="html.register.error.password.pattern"/>');
		$("#div_password_error").css("display", "block");
	}
}
</script>